// SPDX-License-Identifier: GPL-2.0-or-later
// Copyright (c) 2023 Yevhen Babiichuk (DustDFG)

#include <DotSort/View/ITube.hpp>

#include <cstdint>
#include <vector>
#include <optional>

namespace View
{

ITube::ITube(uint8_t size) : size(size)
{}

void ITube::fillSlotsDots(const std::vector<uint8_t>& dots)
{
	for(uint8_t i = 0; i < this->size; ++i)
	{
		std::optional<uint8_t> dot;

		if(dots.size() <= i)
		{
			dot = std::nullopt;
		}
		else
		{
			dot = dots[i];
		}
		this->fillSlotDot(i, dot);
	}
}

void ITube::fillSlotsTube()
{

	this->fillSlotTubePart(0, 2);
	for(uint8_t i = 1; i < (this->size - 1); ++i)
	{
		this->fillSlotTubePart(i, 1);
	}
	this->fillSlotTubePart(this->size - 1, 0);
}

void ITube::fillSlotsSelectedTube()
{

	this->fillSlotSelectedTubePart(0, 2);
	for(uint8_t i = 1; i < (this->size - 1); ++i)
	{
		this->fillSlotSelectedTubePart(i, 1);
	}
	this->fillSlotSelectedTubePart(this->size - 1, 0);
}

}
